import request from '@/config/axios'
import { BlockItem, IndexItem } from '@/views/SysContent/types/flexDatalib'
type newGroupItem = {
  block_id: number
  index_name: string
  frequency: string
  unit: string
}

export const RetrieveBlock = async (): Promise<IResponse> => {
  return request.get({ url: '/v1/admin/flexdatalib/block/retrieve/' })
}
export const CreateBlock = async (data: BlockItem): Promise<IResponse> => {
  return request.post({ url: '/v1/admin/flexdatalib/block/create/', data })
}

export const RetrieveGroup = async (bid: number): Promise<IResponse> => {
  return request.get({ url: '/v1/admin/flexdatalib/blockIndexGroup/retrieve/', params: { bid } })
}
export const CreateGroup = async (data: newGroupItem): Promise<IResponse> => {
  return request.post({
    url: '/v1/admin/flexdatalib/blockIndexGroup/create/',
    data
  })
}

export const RetrieveGroupIndex = async (
  bgid: number,
  ven: string | undefined
): Promise<IResponse> => {
  return request.get({
    url: '/v1/admin/flexdatalib/blockGroupIndex/retrieve/',
    params: { bgid, ven }
  })
}

export const CreateGroupIndex = async (data: IndexItem): Promise<IResponse> => {
  return request.post({
    url: '/v1/admin/flexdatalib/blockGroupIndex/create/',
    data
  })
}
